/*
 * Copyright (C) 2015  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-SDL2/specific/view/draw_vector_universe.h"
#include "PlanetWars2dRT-SDL2/utils/SDL.h"
#include <SDL2_gfxPrimitives.h>
#include "PlanetWars2dRT-core/specific/model/planet.h"


EXTERN_C_BEGIN


bool
SDL_draw_vector_ship_with_defined_color(SDL_Renderer* renderer,
					const ship_t* ship,
					Uint8 red, Uint8 green, Uint8 blue,
					Uint8 alpha,
					FILE* error_stream)
{
  bool result = boxRGBA(renderer,
			ship->position_current.x,
			ship->position_current.y,
			ship->position_current.x + ship->size.x,
			ship->position_current.y + ship->size.y,
			red, green, blue, alpha) == 0;
  if(!result)
    {
      fprintf(error_stream, "A ship was not rendered!\n");
      SDL_print_error();
    }
  return result;
}

bool
SDL_draw_vector_planet_with_defined_color(SDL_Renderer* renderer,
					  const planet_t* planet,
					  Uint8 red, Uint8 green, Uint8 blue,
					  Uint8 alpha,
					  FILE* error_stream)
{
  bool result = filledCircleRGBA(renderer,
				 planet_get_center_position_x(planet),
				 planet_get_center_position_y(planet),
				 planet_get_radius(planet),
				 red, green, blue, alpha) == 0;
  if(!result)
    {
      fprintf(error_stream, "A planet was not rendered!\n");
      SDL_print_error();
    }
  return result;
}

bool
SDL_draw_vector_planets_with_defined_color(SDL_Renderer* renderer,
					   const planet_t* planets, size_t nb,
					   Uint8 red, Uint8 green, Uint8 blue,
					   Uint8 alpha,
					   FILE* error_stream, bool stop_on_error)
{
  bool success = true;
  for(size_t i=0; i < nb; ++i)
    {
      if(!SDL_draw_vector_planet_with_defined_color(renderer,
						    &planets[i],
						    red, green, blue, alpha,
						    error_stream))
	{
	  if(stop_on_error)
	    {
	      return false;
	    }
	  else
	    {
	      success = false;
	    }
	}
    }
  return success;
}


EXTERN_C_END
